package com.xdm.ds.adapter.file;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import xwt.ImplementationWrapper;

import com.xdm.ds.XmItem;

public class FileItem extends ImplementationWrapper implements XmItem {

	public FileItem(String path) {
		this.setImplementation(new File(path));
	}

	public FileItem(File file) {
		this.setImplementation(file);
	}

	public List<XmItem> getChildren() {
		List<XmItem> result = new ArrayList<XmItem>();
		File[] files = ((File) this.getImplementation()).listFiles();
		int length = files.length;
		for (int i = 0; i < length; i++) {
			result.add(new FileItem(files[i]));
		}
		return result;
	}

	public String getName() {
		return ((File) this.getImplementation()).getName();
	}

	public String getParent() {
		return ((File) this.getImplementation()).getParent();
	}

	public XmItem getParentItem() {
		return new FileItem(((File) this.getImplementation()).getParentFile());
	}

	public String getPath() {
		return ((File) this.getImplementation()).getPath();
	}

	public boolean isDirectory() {
		return ((File) this.getImplementation()).isDirectory();
	}

}
